package day9.homework;
//实现一个多线程统计出1-100之间  2、3、5的倍数有哪些?
//   线程1先展示一共2的倍数有哪些
//   线程2再展示一共3的倍数有哪些
//   线程3最后展示一共5的倍数有哪些
public class PrintDemo implements Runnable{
    int n;
    Thread thread;
    public PrintDemo(int n,Thread thread) {
        this.n = n;
        this.thread = thread;
    }
    public void run() {
        if (thread!=null){
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        String name = Thread.currentThread().getName();
        for (int i = 1; i <= 100; i++) {
            if (i%n == 0){
                System.out.println(name+"求出的"+n+"的倍数:"+i);
            }
        }
    }
    public static void main(String[] args) {
        Thread t1 = new Thread(new PrintDemo(2,null),"线程1");
        Thread t2 = new Thread(new PrintDemo(3,t1),"线程2");
        Thread t3 = new Thread(new PrintDemo(5,t2),"线程3");
        t1.start();
        t2.start();
        t3.start();
    }
}
